<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/myjs/people/people.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="empId" value="${requestScope.emp.empId}">
            <div class="layui-form-item">
                <label for="empName" class="layui-form-label">
                    <span class="x-red">*</span>员工姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="empName" value="${requestScope.emp.empName}" name="empName" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block" style="width: 190px">
                    <select id="sex" name="sex" data-value="${requestScope.emp.sex}" lay-verify="required">
                        <option value="0">男</option>
                        <option value="1">女</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属部门</label>
                <div class="layui-input-block" style="width: 190px">
                    <select name="departmentId" data-value="${requestScope.emp.departmentId}" lay-verify="required">

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="idCode" class="layui-form-label">
                    <span class="x-red">*</span>身份证号</label>
                <div class="layui-input-inline">
                    <input type="text" id="idCode" value="${requestScope.emp.idCode}" name="idCode" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="education" class="layui-form-label">
                    <span class="x-red">*</span>学历</label>
                <div class="layui-input-inline">
                    <input type="text" id="education" value="${requestScope.emp.education}" name="education" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="degree" class="layui-form-label">
                    <span class="x-red">*</span>学位</label>
                <div class="layui-input-inline">
                    <input type="text" id="degree" value="${requestScope.emp.degree}" name="degree" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="major" class="layui-form-label">
                    <span class="x-red">*</span>专业</label>
                <div class="layui-input-inline">
                    <input type="text" id="major" value="${requestScope.emp.major}" name="major" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="educationForm" class="layui-form-label">
                    <span class="x-red">*</span>受教育形式</label>
                <div class="layui-input-inline">
                    <input type="text" id="educationForm" value="${requestScope.emp.educationForm}" name="educationForm"
                           required="" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="graduateSchool" class="layui-form-label">
                    <span class="x-red">*</span>毕业院校</label>
                <div class="layui-input-inline">
                    <input type="text" id="graduateSchool" value="${requestScope.emp.graduateSchool}"
                           name="graduateSchool" required="" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="birthday" class="layui-form-label">
                    <span class="x-red">*</span>生日</label>
                <div class="layui-input-inline">
                    <input type="text" id="birthday" value="<fmt:formatDate value="${requestScope.emp.birthday}"
                                                        pattern="yyyy-MM-dd"/>" name="birthday" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="joinDate" class="layui-form-label">
                    <span class="x-red">*</span>入职日期</label>
                <div class="layui-input-inline">
                    <input type="text" id="joinDate" value="<fmt:formatDate value="${requestScope.emp.joinDate}"
                                                        pattern="yyyy-MM-dd"/>" name="joinDate" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="status" class="layui-form-label">
                    <span class="x-red">*</span>员工状态</label>
                <div class="layui-input-inline">
                    <input type="text" id="status" value="${requestScope.emp.status}" name="status" required=""
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="sub" class="layui-form-label"></label>
                <button class="layui-btn" id="sub" lay-filter="edit" lay-submit="">编辑</button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer', 'jquery', 'laydate'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;
        //页面加载时执行
        $(function () {
            depList()
        })

        laydate.render({
            elem: '#birthday'
        });
        laydate.render({
            elem: '#joinDate'
        });


        function depList() {
            $.ajax({
                url: "${pageContext.request.contextPath}/people/dep/list",
                type: "get",
                success(res) {
                    let list = res.data.list
                    if (res.success) {
                        let select = $("select[name=departmentId]")
                        let option = ""
                        for (let i = 0; i < list.length; i++) {
                            option += "<option value='" + list[i].departmentId + "'>" + list[i].departmentName + "</option>"
                        }
                        select.append(option)
                        //将对应的下拉框选中
                        let departmentId = select[0].dataset.value
                        let sex = $("select[name=sex]")[0].dataset.value
                        $("select[name=departmentId]").find("option[value='" + departmentId + "']").attr("selected", "selected");
                        $("select[name=sex]").find("option[value='" + sex + "']").attr("selected", "selected");
                        //从新渲染
                        form.render("select");
                    } else {
                        layer.alert("权限列表获取失败", {icon: 2})
                    }
                }
            })
        }

        //监听提交
        form.on('submit(edit)',
            function (data) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/people/emp/edit",
                    type: "post",
                    data: data.field,
                    success(res) {
                        if (res.success) {
                            layer.alert("编辑成功", {
                                    icon: 6
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        } else {
                            layer.alert("编辑失败", {
                                icon: 2
                            });
                        }
                    }
                })
                return false;
            });

    });

</script>
</body>

</html>
